package com.scuec.tourismwebsite.mapper;

import com.scuec.tourismwebsite.entity.BoutiqueTour;
import org.apache.ibatis.annotations.*;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;

@Mapper
public interface BoutiqueTourMapper {
    @Select("SELECT * FROM boutique_tour WHERE tour_name LIKE CONCAT('%', #{tourName}, '%')")
    List<BoutiqueTour> searchByTourName(String tourName);

    @Select("SELECT * FROM boutique_tour")
    List<BoutiqueTour> findAll();

    @Select("SELECT * FROM boutique_tour WHERE boutique_id = #{id}")
    BoutiqueTour findById(Integer boutique_id);

    @Insert("INSERT INTO boutique_tour (" +
            "tour_name, description, price, availability, " +
            "start_date, end_date, create_date, image_url) " +
            "VALUES (" +
            "#{tour_name}, #{description}, #{price}, #{availability}, " +
            "#{start_date}, #{end_date}, NOW(), #{image_url})")
    int insert(BoutiqueTour boutiqueTour);

    @Update("UPDATE boutique_tour SET tour_name = #{tour_name}, description = #{description}, price = #{price}, " +
            "availability = #{availability}, start_date = #{start_date}, end_date = #{end_date}, " +
            "image_url = #{image_url} WHERE boutique_id = #{boutique_id}")
    int update(BoutiqueTour boutiqueTour);

    @Delete("DELETE FROM boutique_tour WHERE boutique_id = #{id}")
    int delete(Integer id);

    @Update("UPDATE boutique_tour SET image_url = #{image_url} WHERE boutique_id = #{boutique_id}")
    int updatePhoto(@Param("image_url") String image_url, @Param("boutique_id") Integer boutique_id);

    @Update("UPDATE boutique_tour SET  availability = #{availability}, start_date = #{start_date}, end_date = #{end_date}, image_url = #{image_url} WHERE boutique_id = #{boutique_id}")
    int update2(BoutiqueTour boutiqueTour);

    @Update("UPDATE boutique_tour SET availability = availability - 1 WHERE boutique_id = #{boutique_id} AND `availability` > 0")
    int decreaseAvailability(@Param("boutique_id") Integer boutique_id);
}